package com.ydd.controller.admin;


import com.ydd.dto.RolePageDTO;
import com.ydd.dto.SysUpdateDTO;
import com.ydd.dto.SysUserAddDTO;
import com.ydd.dto.SysUserDTO;
import com.ydd.result.HMPageResult;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.ISysUserService;
import com.ydd.vo.UserRoleVO;
import com.ydd.vo.UserRowInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author hgz
 * @since 2023-05-30
 */
@RestController
@RequestMapping("/admin/sys_user")
@Slf4j
@Api("管理员管理相关接口")
public class SysUserController {
    @Autowired
    private ISysUserService iSysUserService;


    /**
     * 用户列表分页查询
     *
     * @param sysUserDTO
     * @return
     */
    @GetMapping("list")
    @ApiOperation("用户列表分页查询")
    public Result<HMPageResult<UserRoleVO>> pageQuery(SysUserDTO sysUserDTO) {

        log.info("用户列表分页查询：{}", sysUserDTO);

        HMPageResult<UserRoleVO> pageResult = iSysUserService.pageQuery(sysUserDTO);

        return Result.success(pageResult);
    }


    /**
     * 管理员添加
     *
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("管理员添加")
    public Result addUser(@RequestBody SysUserAddDTO sysUserAddDTO) {

        log.info("管理员添加:{}", sysUserAddDTO);

        iSysUserService.addUser(sysUserAddDTO);

        return Result.success();
    }


    /**
     * 管理员删除
     *
     * @param id
     * @return
     */

    @GetMapping("/del")
    @ApiOperation("管理员删除")
    public Result SysUserdelect(String id) {


        log.info(" 管理员删除:{}", id);

        iSysUserService.SysUserdelect(id);

        return Result.success();
    }


    /**
     * 管理员详情
     *
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiOperation("管理员详情")
    public Result<UserRowInfoVO> UserRowInfo(String id) {

        log.info("管理员详情:{}", id);

        UserRowInfoVO page = iSysUserService.UserRowInfo(id);

        return Result.success(page);
    }


    @PostMapping("/update")
    @ApiOperation("管理员修改")
    public Result UserUpdate(@RequestBody SysUpdateDTO sysUpdateDTO){

        iSysUserService.UserUpdate(sysUpdateDTO);

        return Result.success();
    }

}
